package com.situ.mall.admin.controller;


import com.situ.mall.admin.vo.ResultVO;
import com.situ.mall.admin.vo.TableVO;
import com.situ.mall.admin.entity.User;
import com.situ.mall.admin.service.IUserService;
import com.situ.mall.common.util.RequestUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lwj
 * @since 2023-09-08
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @GetMapping("/page")
    public String page() {
        return "user";
    }

    @GetMapping("/list")
    @ResponseBody
    public TableVO list(Integer page, Integer limit, String username, String name, String status) {
        return userService.select(page, limit, username, name, status);
    }

    @PostMapping("/save")
    @ResponseBody//不找页面
    public void save2(User u) {
        u.setAvatar(u.getAvatar().replace("D:", ""));
        userService.save2(u);
    }

    // restful风格/category/info/id
    @GetMapping("/info/{userId}")
    @ResponseBody
    public User info(@PathVariable("userId") Integer id) {

        return userService.info(id);
    }


//    @PostMapping("/{userId}")
//    @ResponseBody
//    public void delete(@PathVariable("userId") Integer Id){
//
//        userService.delete(Id);
//    }


    @PostMapping("/delete")
    @ResponseBody
    public void delete(String ids) {
        userService.delete2(ids);
    }

    @PostMapping("checkPassword")
    @ResponseBody
    public ResultVO checkPassword(String password) {
        User u = (User) RequestUtil.getCurrent();
        return userService.checkPassword(password, u.getPassword());
    }

    @PostMapping("resetPassword")
    @ResponseBody
    public ResultVO resetPassword(String password1, String password2) {

        return userService.resetPassword(password1, password2);
    }
}
